<#include '/admin/sonheader.html' >
<#assign dataformat="com.enation.framework.directive.DateformateDirective"?new()/>
<style>
.layui-form-pane .layui-form-label{
 width:25%;
}
.layui-form-item input{
  width: 77%;
}
</style>
<div class="main">
    <!--表单区域  -->
	<form id="editbonusTypeForm" class="layui-form layui-form-pane" action="" enctype="multipart/form-data" style="padding-top:10px">
  		<div class="layui-form-item">
    		<label class="layui-form-label">优惠券识别码：</label>
    		<div class="layui-input-block">
      			<input type="text" name="recognition" maxlength="60"  value="${bonusType.recognition}" lay-verify="recognition" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">类型名称：</label>
    		<div class="layui-input-block">
      			<input type="text" name="type_name" maxlength="60" value="${bonusType.type_name}" lay-verify="type_name" autocomplete="off" class="layui-input">
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">红包金额：</label>
    		<div class="layui-input-block">
      			<input type="text" name="type_money" maxlength="7" value="${bonusType.type_money}"  lay-verify="type_money" autocomplete="off" class="layui-input _left">
      			<div class="layui-form-mid layui-word-aux">此类红包可以抵消的金额</div>
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">最小订单金额：</label>
    		<div class="layui-input-block">
      			<input type="text" name="min_goods_amount" maxlength="7" value="${bonusType.min_goods_amount}" lay-verify="min_goods_amount" autocomplete="off" class="layui-input _left">
      			<div class="layui-form-mid layui-word-aux">只有商品总金额达到这个数的订单才能使用这种红包</div>
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">如何发放此类型红包：</label>
    		<div class="layui-input-block">
      			<input type="radio" name="send_type" value="0" title="按用户发放" <#if bonusType.send_type==0>checked</#if>>
     			<input type="radio" name="send_type" value="3" title="线下发放的红包" <#if bonusType.send_type==3>checked</#if>>
    		</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">发放开始日期：</label>
    		<div class="layui-input-block">
      			<input type="text" class="layui-input _left" name="sendTimeStart"   id="sendTimeStart" disabled="disabled" value="<@dataformat time="now" pattern="yyyy-MM-dd hh:mm:ss" />"
    		</div>
    		<div class="layui-form-mid layui-word-aux" style="width: 45%;">只有当前时间介于起始日期和截止日期之间时，此类型的红包才可以发放</div>
  		</div>
  		
  		<div class="layui-form-item">
    		<label class="layui-form-label">发放结束日期：</label>
    		<div class="layui-input-block">
      			<input type="text" class="layui-input " name="sendTimeEnd"   id="sendTimeEnd" disabled="disabled" value="<@dataformat time="nextmonth" pattern="yyyy-MM-dd hh:mm:ss" />"
    		</div>
  		</div>
  		
  		<div class="layui-form-item" style="padding-top: 8px;margin-bottom:0;">
    		<label class="layui-form-label">使用起始日期：</label>
    		<div class="layui-input-block">
  				<input class="layui-input _left" name="useTimeStart" id="useTimeStart" value="<@dataformat time='${bonusType.use_start_date}' pattern='yyyy-MM-dd hh:mm:ss'/>" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
			    <div class="layui-form-mid layui-word-aux" style="width: 45%;">只有当前时间介于起始日期和截止日期之间时，此类型的红包才可以使用</div>
			</div>
  		</div>
  		<input type="hidden" name="type_id" value="${bonusType.type_id}">
  		<div class="layui-form-item" style="padding-top: 8px;margin-bottom:0;'">
    		<label class="layui-form-label">使用结束日期：</label>
    		<div class="layui-input-block">
  				<input class="layui-input _left" name="useTimeEnd" id="useTimeEnd"  value="<@dataformat time='${bonusType.use_end_date}' pattern='yyyy-MM-dd hh:mm:ss'/>" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD hh:mm:ss'})">
			</div>
  		</div>
  		
  		<div class="layui-layer-btn layui-layer-btn-" style="padding:8px 12px;z-index:1000;position: fixed;left: 1px;width: 97%;height: 50px; background:rgba(230,230,230,0.8)"> 
  			<a class="layui-layer-btn0" type="submit" id="savebtn" lay-submit="" lay-filter="edit_bonus_type">保存</a>
  			<a class="layui-layer-btn1">取消</a>
  		</div>
  	</form>
</div>

<script type="text/javascript">
var index = parent.layer.getFrameIndex(window.name);

layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form()
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate;
    var check= /^(([1-9]+[.]?[0-9]{1,2})|[1-9])$/;  
    //校验
    form.verify({
    	recognition:function(value){
    		if($.trim(value) == ""){
    			return "请输入优惠券识别码";
    		}
    	},
    	type_name:function(value){
    		if($.trim(value) == ""){
    			return "请输入类型名称";
    		}
    	},
    	type_money:function(value){
    		if($.trim(value) == ""){
    			return "请输入红包金额";
    		}
    		if(!check.test(value)){  
            	return "请输入大于零的数";
            }
    	},
    	min_goods_amount:function(value){
    		if($.trim(value) == ""){
    			return "请输入最小订单金额";
    		}
    		if(!check.test(value)){  
            	return "请输入大于零的数";
            }
    	}
    	
    });
    	
    $(".layui-layer-btn1").click(function(){
    	parent.layer.close(index);
    });
    
  //类型切换
	$(function() {
		$("input[type=radio]").click(
				function() {
					var value = this.value;
					if (value == 1 || value == 2) {
						$('#sendTimeStart').datebox('enable');
						$('#sendTimeEnd').datebox('enable'); 
					} else {
						$('#sendTimeStart').datebox('disable');
						$('#sendTimeEnd').datebox('disable');
					}

					if (value == 2) {
						$("#min_tr").show();
					} else {
						$("#min_tr").hide();
					}
			});
	});
		
		//修改保存
        form.on('submit(edit_bonus_type)', function(data){
          var amount = parseInt($("input[name='min_goods_amount']").val());
      	  var money = parseInt($("input[name='type_money']").val());
      	  if(amount < money){
      		  parent.$.Loading.error("最小订单金额不能小于红包金额！");
      		  return false;
      	  }
    		var options = {
    			url : ctx+"/shop/admin/bonus-type/save-edit.do",
    			type : "post",
    			dataType : 'json',
    			success : function(result) {
    				if (result.result == 1) {
    					parent.$.Loading.success(result.message);
    					parent.layer.close(index);
    					parent.table.ajax.url('${ctx}/shop/admin/bonus-type/list-json.do').load();
    				}
    				if (result.result == 0) {
    					parent.$.Loading.error(result.message);
    				}
    			},
    			error : function(e) {
    				parent.$.Loading.error("出现错误 ，请重试");
    			}
    		};
    		$("#editbonusTypeForm").ajaxSubmit(options);
    		return false;
        });
});
</script>